import java.util.Scanner;

public class NGuessNumber {
    public static int[] generateAnswer(){

        int a[] =new int[4];
       do { for (int i = 0; i < 4; i++) {
               int x = (int) (Math.random() * 10);
               int m = 0;
               for (int j = i - 1; j > 0; j--) {
                   if (a[j] == x) {
                       m = 1;
                   }
               }
               if (m != 1) {
                   a[i] = x;
               } else {
                   i--;
               }
           }
       }while (!((a[0]!=0) && (a[0]!=a[1]) && (a[0]!=a[2]) && (a[0]!=a[3]) && (a[1]!=a[2]) && (a[1]!=a[3]) && (a[2]!=a[3])));
        return a;

}
    public static int[] getPlayerInput() {
        Scanner sc = new Scanner(System.in);
        int a[]=new int[4];
        for (int i = 0; i <a.length ; i++) {
            a[i]=sc.nextInt();
    }
        return a;
    }


    public static boolean isWin(int[] a) {
        return a[0] == 4;
    }


    public static int[] compareGuessAnswer(int[] a, int[] b) {
        int c[] = new int[4];
        c[0]=c[1]=0;
        for (int i = 0; i <c.length ; i++) {
            if (a[i]==b[i]){
                c[1]++;
            }
            for (int j = 0; j <c.length ; j++) {
                if (a[i]==b[j]){
                    c[0]++;
                }
            }
        }

        return c;
    }

    public static void main(String[] args) {
        aa:while (true){
            System.out.println("请输入0-9的数字，以空格分割！");
            int[] answer = generateAnswer();
            // for (int i = 0; i < answer.length; i++) {
            //     System.out.print(answer[i]+" ");
            // }
            int[] input = getPlayerInput();
            while (true){
                int[] ints = compareGuessAnswer(answer, input);
                boolean win = isWin(ints);
                if(win){
                    System.out.println("恭喜您获得胜利！");
                    System.out.println("是否再玩一次（y/n）");
                    Scanner scanner = new Scanner(System.in);
                    String next = scanner.next();
                    if(next.equals("y")){
                        continue aa;
                    }
                    return;
                }else{
                    System.out.println("猜错了，请重新输入");
                    System.out.println("提示：");
                    System.out.println("您猜对了"+ints[0]+"个数字.");
                    System.out.println("您猜对了"+ints[1]+"个位置.");
                    input = getPlayerInput();
                }

            }
        }

    }

}